package com.example.springbootdisconf.config;

import com.baidu.disconf.client.DisconfMgrBean;
import com.baidu.disconf.client.DisconfMgrBeanSecond;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 说明
 *
 * @author 代镇位
 * @date 2020年04月11日 15:43
 */
@Configuration
public class DisconfConfiguration {

    @Bean(destroyMethod = "destroy")
    public DisconfMgrBean getDisconfMgrBean() {
        DisconfMgrBean disconfMgrBean = new DisconfMgrBean();
        //你的需要被扫描的包
        disconfMgrBean.setScanPackage("com.example.springbootdisconf");
        return disconfMgrBean;
    }

    @Bean(destroyMethod = "destroy", initMethod = "init")
    public DisconfMgrBeanSecond getDisconfMgrBean2() {
        return new DisconfMgrBeanSecond();
    }

//    @Bean(name = "reloadablePropertiesFactoryBean")
//    public ReloadablePropertiesFactoryBean reloadablePropertiesFactoryBean() {
//        ReloadablePropertiesFactoryBean propertiesFactoryBean = new ReloadablePropertiesFactoryBean();
//        propertiesFactoryBean.setSingleton(true);
//
//        // disconf配置的文件
//        List<String> fileNames = new ArrayList<>();
//        fileNames.add("classpath*:simple.properties");
//        propertiesFactoryBean.setLocations(fileNames);
//        return propertiesFactoryBean;
//    }
//
//    @Bean(name = "propertyPlaceholderConfigurer")
//    public PropertyPlaceholderConfigurer propertyPlaceholderConfigurer(ReloadablePropertiesFactoryBean reloadablePropertiesFactoryBean) {
//        PropertyPlaceholderConfigurer placeholderConfigurer = new PropertyPlaceholderConfigurer();
//        placeholderConfigurer.setIgnoreResourceNotFound(true);
//        placeholderConfigurer.setIgnoreUnresolvablePlaceholders(true);
//        try {
//            Properties properties = reloadablePropertiesFactoryBean.getObject();
//            placeholderConfigurer.setProperties(properties);
//        } catch (IOException e) {
//            throw new RuntimeException("unable to find properties", e);
//        }
//        return placeholderConfigurer;
//    }
}
